FROM centos:7

ENV  LANG=en_US.UTF-8 \
     LANGUAGE=en_US:en
#	 LC_ALL=en_US.UTF-8

ARG LIBERICA_VERSION=17.0.10
ARG LIBERICA_BUILD=13
ARG LIBERICA_VARIANT=jre
ARG LIBERICA_ROOT=/usr/lib/jvm/${LIBERICA_VARIANT}-${LIBERICA_VERSION}-bellsoft

ARG LIBERICA_USE_LITE=0
ARG LIBERICA_GENERATE_CDS=false

RUN LIBERICA_ARCH='' \
  &&    LIBERICA_ARCH_TAG='' \
  &&    case `uname -m` in \
              x86_64) \
                  LIBERICA_ARCH="amd64" \
                  ;; \
              i686) \
                  LIBERICA_ARCH="i586" \
                  ;; \
              aarch64) \
                  LIBERICA_ARCH="aarch64" \
                  ;; \
              armv[67]l) \
                  LIBERICA_ARCH="arm32-vfp-hflt" \
                  ;; \
              *) \
                  LIBERICA_ARCH=`uname -m` \
                  ;; \
        esac \
  &&    yum install -y fontconfig \
  &&    mkdir -p $LIBERICA_ROOT \
  &&    mkdir -p /tmp/java \
  &&    RSUFFIX="" \
  &&    if [ "$LIBERICA_USE_LITE" = "1" ]; then RSUFFIX="-lite"; fi \
  &&    LIBERICA_BUILD_STR=${LIBERICA_BUILD:+"+${LIBERICA_BUILD}"} \
  &&    PKG=`echo "bellsoft-${LIBERICA_VARIANT}${LIBERICA_VERSION}${LIBERICA_BUILD_STR}-linux-${LIBERICA_ARCH}${RSUFFIX}.tar.gz"` \
  &&    PKG_URL="https://download.bell-sw.com/java/${LIBERICA_VERSION}${LIBERICA_BUILD_STR}/${PKG}" \
  &&    echo "Download ${PKG_URL}" \
  &&    curl -SL "${PKG_URL}" -o /tmp/java/jre.tar.gz \
  &&    SHA1=$(curl -fSL "https://download.bell-sw.com/sha1sum/java/${LIBERICA_VERSION}${LIBERICA_BUILD_STR}" | grep ${PKG} | grep -v json | cut -f1 -d' ') \
  &&    echo "${SHA1} */tmp/java/jre.tar.gz" | sha1sum -c - \
  &&    tar xzf /tmp/java/jre.tar.gz -C /tmp/java \
  &&    find "/tmp/java/${LIBERICA_VARIANT}-${LIBERICA_VERSION}${RSUFFIX}" -maxdepth 1 -mindepth 1 -exec mv "{}" "${LIBERICA_ROOT}/" \; \
  &&    ln -s $LIBERICA_ROOT /usr/lib/jvm/jre \
  &&    yum clean all \
  &&    rm -rf /var/cache/yum \
  &&    rm -rf /var/lib/rpm/__db* \
  &&    rpm --rebuilddb \
  &&    (ls /usr/lib/jvm/jre/lib/client 1>/dev/null 2>&1 && (rm -rf /usr/lib/jvm/jre/lib/client && sed -i 's#-client\s\+KNOWN#-client IGNORE#g' /usr/lib/jvm/jre/lib/jvm.cfg) || : ) \
  &&    if [ $LIBERICA_GENERATE_CDS = true ]; then                       \
        ${LIBERICA_ROOT}/bin/java -XX:+UseCompressedOops -Xshare:dump;   \
        ${LIBERICA_ROOT}/bin/java -XX:-UseCompressedOops -Xshare:dump;   \
    else                                                                 \
        find ${LIBERICA_ROOT} -name "classes*.jsa" -exec rm {} \; ;      \
    fi                               \
  &&    rm -rf /tmp/java             \
  &&    rm -rf /tmp/hsperfdata_root

ENV JAVA_HOME=${LIBERICA_ROOT} \
	PATH=${LIBERICA_ROOT}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
